from app.services.business.gaolu_diagnose.ind.abstract_ind import AbstractInd
from typing import List

class CG_LT_GL_GL04_DWPJ(AbstractInd):

    def get_name(self):
        return "CG_LT_GL_GL04_DWPJ"

    def get_sql(self, params) -> list:
        sql_DWDB = """    
                SELECT mean(value) AS CG_LT_GL_GL04_DWDB  FROM "CG_LT_GL_GL04_DWDB"   
                where time > '{dt_start_tz}' and time < '{dt_end_tz}'
                """.format(**params)

        sql_DWDN = """
                SELECT mean(value) AS CG_LT_GL_GL04_DWDN  FROM "CG_LT_GL_GL04_DWDN"   
                where time > '{dt_start_tz}' and time < '{dt_end_tz}'
                """.format(**params)

        sql_DWXB = """
                SELECT mean(value) AS CG_LT_GL_GL04_DWXB  FROM "CG_LT_GL_GL04_DWXB"   
                where time > '{dt_start_tz}' and time < '{dt_end_tz}'
                """.format(**params)

        sql_DWXN = """
                SELECT mean(value) AS CG_LT_GL_GL04_DWXN  FROM "CG_LT_GL_GL04_DWXN"   
                where time > '{dt_start_tz}' and time < '{dt_end_tz}'
                """.format(**params)

        return [sql_DWDB, sql_DWDN, sql_DWXB, sql_DWXN]

    @AbstractInd.cache_wrapper
    def get_result(self):
        sql_list: List[str] = self.get_sql(self.params)
        client = self.influx_client

        #####字段1
        DWDB = sql_list[0]
        result_set = list(client.query(DWDB))
        DWDB = self.get_influx_result(result_set, "CG_LT_GL_GL04_DWDB")

        #####字段2
        DWDN = sql_list[1]
        result_set = list(client.query(DWDN))
        DWDN = self.get_influx_result(result_set, "CG_LT_GL_GL04_DWDN")

        #####字段3
        DWXB = sql_list[2]
        result_set = list(client.query(DWXB))
        DWXB = self.get_influx_result(result_set, "CG_LT_GL_GL04_DWXB")

        #####字段4
        DWXN = sql_list[3]
        result_set = list(client.query(DWXN))
        DWXN = self.get_influx_result(result_set, "CG_LT_GL_GL04_DWXN")


        return round((float(DWDB) + float(DWDN) + float(DWXB)+ float(DWXN))/ 4, 2)